package com.lz.interceptor;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Logininterceptor extends HandlerInterceptorAdapter{

    //登录拦截器，进入controller前执行

    @Override
    public boolean preHandle
            (HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
         //判断session中是否有key。有的话继续用户的操作
        if(request.getSession().getAttribute ("SESSION_USER")!=null){
           return true;
        }
    //没有登录就进入 登入界面
        response.sendRedirect(request.getContextPath()+"/user/search.html");
        return false;
    }
}
